package io.renren.modules.simida.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import io.renren.common.utils.Constant;
import io.renren.common.utils.StringUtil;
import io.renren.datasource.annotation.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.simida.dao.UserDataDao;
import io.renren.modules.simida.entity.UserDataEntity;
import io.renren.modules.simida.service.UserDataService;


@Service("userDataService")
public class UserDataServiceImpl extends ServiceImpl<UserDataDao, UserDataEntity> implements UserDataService {
    @Autowired
    private UserDataDao userDataDao;
    @Override
    @DataSource(Constant.DB_SLAVE_SIMIDA)
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<UserDataEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtil.isNotEmpty(params.get("userId")),"user_id",params.get("userId"));
        IPage<UserDataEntity> page = this.page(
                new Query<UserDataEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    @DataSource(Constant.DB_SLAVE_SIMIDA)
    public List<JSONObject> queryCountGroupByDeviceType() {

        return userDataDao.queryCountGroupByDeviceType();
    }

    @Override
    @DataSource(Constant.DB_SLAVE_SIMIDA)
    public List<JSONObject> queryCountGroupByVersion() {
        return userDataDao.queryCountGroupByVersion();
    }

}